package com.graduate.examapp

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*
import java.util.Deque

/**
 * Instrumented test, which will execute on an Android device.
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
    @Test
    fun useAppContext() {
        // Context of the app under test.
        val appContext = InstrumentationRegistry.getInstrumentation().targetContext
        assertEquals("com.graduate.examapp", appContext.packageName)
    }
    //private val operators = mutableSetOf<Char>('+', '-', '*', '/')
    //fun arithmeticParse(expression: String): String {
    //    //获取计算表达式中的数字
    //    val numbers = expression.split("+", "-", "*", "/")
    //    val length = expression.length
    //    val startsWithSigned = expression.startsWith("-")
    //    val stack = ArrayDeque<String>()
    //    //以负数开头 预处理
    //    if (startsWithSigned) {
    //        stack.addLast("0")
    //        stack.addLast("-")
    //    }
    //    val operatorList = mutableListOf<String>()
    //    //获取 计算表达式中的操作符
    //    for (i in 1 until  length) {
    //        if (operators.contains(expression[i])) {
    //            operatorList.add(expression[i].toString())
    //        }
    //    }
    //
    //    val mLength = numbers.size
    //    val nLength = operatorList.size
    //    var m = 0
    //    var n = 0
    //    var i = 1
    //    //第一次栈计算 计算乘除
    //    while (m < mLength && n < nLength) {
    //        if (i % 2 != 0) {
    //            //下标奇数 数字入栈
    //            if (stack.lastOrNull() == "*" ) {
    //                val operate = stack.removeLast()
    //                val another = stack.removeLast()
    //                val res = computeMultiple(another, numbers[m])
    //                stack.addLast(res)
    //            } else if (stack.lastOrNull() == "/") {
    //                val operate = stack.removeLast()
    //                val another = stack.removeLast()
    //                val res = computeDivide(another, numbers[m])
    //                stack.addLast(res)
    //            } else {
    //                stack.addLast(numbers[m])
    //            }
    //            m++
    //        } else {
    //            //下标偶数 操作符入栈入栈
    //            stack.addLast(operatorList[n++])
    //        }
    //        i++
    //    }
    //    //第二次栈操作 计算加减
    //    val stackSecond = ArrayDeque<String>()
    //    //添加在占位符
    //    stackSecond.addLast("#")
    //    while (stack.isNotEmpty()) {
    //        //逆向输出 前面的结果栈
    //        val before = stack.removeFirst()
    //        if (stackSecond.last() == "+") {
    //            val operate = stackSecond.removeLast()
    //            val another = stackSecond.removeLast()
    //            val res = computeAdd(before, another)
    //            stackSecond.addLast(res)
    //        } else if (stackSecond.last() == "-") {
    //            val operate = stackSecond.removeLast()
    //            val another = stackSecond.removeLast()
    //            val res = computeSubstract(before, another)
    //            stackSecond.addLast(res)
    //        } else {
    //            stackSecond.addLast(before)
    //        }
    //    }
    //    return stackSecond.last()
    //}
}